library(ggplot2)
library(gapminder)
library(gganimate)
library(gifski)
library(tidyverse)
## ── Attaching packages ────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ tibble 2.1.3 ✔ purrr 0.3.2
## ✔ tidyr 0.8.3 ✔ dplyr 0.8.3
## ✔ readr 1.3.1 ✔ stringr 1.4.0
## ✔ tibble 2.1.3 ✔ forcats 0.4.0
## ── Conflicts ───────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(png)
theme_set(theme_bw())
gapminder_animation <- ggplot(gapminder::gapminder, aes(gdpPercap,
lifeExp,
size = pop,
colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
# scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~ continent) +
# Here comes the gganimate specific bits
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) + ## regulation the actual layers for the animation
ease_aes('linear')
gapminder_animation

## ------------------------------------------------------------------------
# library(av)
# p <- ggplot(airquality,
# aes(x = Day,
# y = Temp)) +
# geom_line(size = 2, colour = 'steelblue') +
# transition_states(state = Month,
# transition_length = 4,
# state_length = 2) +
# shadow_mark(size = 0.3, colour = 'lightgrey')
# animate(p, renderer = av_renderer())
#